import java.io.*;

public class Logger {
    private String FilePath = "log.txt";
    private boolean verbose = false;
    
    public Logger(String FP) {
        this.FilePath = FP;
    }
    
    public Logger(String FP, boolean v) {
        this.FilePath = FP;
        this.verbose = v;
    }
    
    public boolean getVerbose() {
        return verbose;
    }
    
    public void setVerbose(boolean v) {
        verbose = v;
    }
    
    public void log(Throwable throwable) {
        Writer writer = new StringWriter();
        PrintWriter printWriter = new PrintWriter(writer);
        throwable.printStackTrace(printWriter);
        log(writer.toString() + "\n");
    }
    
    public void log(String LogEntry) {
        if (verbose) {
            System.out.println(LogEntry);
        }
        
        try {
            BufferedWriter out = new BufferedWriter(new FileWriter(FilePath, true));
            out.write(LogEntry);
            out.write("\n");
            out.close();
        } catch (IOException e) {
            System.err.println("Error writing to log.");
            System.err.println(e.getMessage());
            e.printStackTrace();
        }
    }
}
